#pragma once
#pragma unmanaged  

#include "cpMeetingServiceMgr.h"
#include "cpPreMeetingServiceMgr.h"
#include "cpAuthServiceMgr.h"


#pragma managed
#include "mcallback.h"


public delegate void AuthCBDelegate(int,int);

public delegate void CbShowStatusDelegate(int, IntPtr status_str);

public delegate void CbClearnUpUserListDelegate();

public delegate void CbSwitchUIPageByTypeDelegate(int);

public delegate void CbUpdateUserListDelegate(int, IntPtr uname,IntPtr uid,bool);

public delegate void PreMeetingCBDelegate(int, int);


using std::cout;




public ref class clsZoomMgr
{
private:
	CAuthServiceMgr *m_pAuthServiceMgr;
	CMeetingServiceMgr *m_pMeetingServiceMgr;
	CPreMeetingServiceMgr *m_preMeetingServiceMgr;
	TheCallBacks *m_pSink;

	bool m_bSDKInit;
public:
	clsZoomMgr(
		CbShowStatusDelegate ^pCBSS,
		CbSwitchUIPageByTypeDelegate ^pCBSUI,
		CbUpdateUserListDelegate ^pCBUUL,
		CbClearnUpUserListDelegate ^pCBCUUL
		);
	int init(const wchar_t* domain, const wchar_t* apikey, const wchar_t* apisec);
	int Login(const wchar_t* email, const wchar_t* password, bool memberme);
	int NormalUserStart(const wchar_t* meetingnumber)
	{
		m_pSink->ShowStatus(0, L"clsZoomMgr::NormalUserStart");

		m_pMeetingServiceMgr->Init();

		ZOOM_SDK_NAMESPACE::StartParam startParam;
		startParam.userType = ZOOM_SDK_NAMESPACE::SDK_UT_NORMALUSER;
		ZOOM_SDK_NAMESPACE::StartParam4NormalUser& normalParam = startParam.param.normaluserStart;
		normalParam.meetingNumber = _wcstoui64(meetingnumber,NULL,10);

		int ret = m_pMeetingServiceMgr->Start(startParam) ? 0 : -1;
		m_pSink->ShowStatus(ret, L"clsZoomMgr::NormalUserStart ret");

		return ret;

	}
	int NormalUserJoin(const wchar_t* meetingnumber,const wchar_t* username, const wchar_t *usertoken)
	{
		m_pSink->ShowStatus(0, L"clsZoomMgr::NormalUserJoin");

		m_pMeetingServiceMgr->Init();

		ZOOM_SDK_NAMESPACE::JoinParam joinParam;
		joinParam.userType = ZOOM_SDK_NAMESPACE::SDK_UT_NORMALUSER;
		ZOOM_SDK_NAMESPACE::JoinParam4NormalUser& normalParam = joinParam.param.normaluserJoin;
		normalParam.meetingNumber = _wcstoui64(meetingnumber, NULL, 10);
		normalParam.userName = username;
		normalParam.psw = usertoken;

		int ret = m_pMeetingServiceMgr->Join(joinParam) ? 0 : -1;
		m_pSink->ShowStatus(ret, L"clsZoomMgr::NormalUserJoin ret");
		return ret;

	}
	int ApiUserStart(const wchar_t* meetingnumber,const wchar_t* username,wchar_t* userId,const wchar_t* usertoken)
	{
		m_pSink->ShowStatus(0, L"clsZoomMgr::ApiUserStart");

		m_pMeetingServiceMgr->Init();
		ZOOM_SDK_NAMESPACE::StartParam startParam;
		startParam.userType = ZOOM_SDK_NAMESPACE::SDK_UT_APIUSER;
		ZOOM_SDK_NAMESPACE::StartParam4APIUser& apiuserParam = startParam.param.apiuserStart;

		apiuserParam.userID = userId;
		apiuserParam.userToken = usertoken;
		apiuserParam.meetingNumber = _wcstoui64(meetingnumber, NULL, 10);
		apiuserParam.userName = username;

		int ret = m_pMeetingServiceMgr->Start(startParam) ? 0 : -1;
		m_pSink->ShowStatus(ret, L"clsZoomMgr::ApiUserStart ret");
		return ret;

	}
	int ApiUserJoin(const wchar_t* meetingnumber,const wchar_t* username, wchar_t* userId, const wchar_t* usertoken)
	{
		m_pSink->ShowStatus(0, L"clsZoomMgr::ApiUserJoin");

		m_pMeetingServiceMgr->Init();

		ZOOM_SDK_NAMESPACE::JoinParam joinParam;
		joinParam.userType = ZOOM_SDK_NAMESPACE::SDK_UT_APIUSER;
		ZOOM_SDK_NAMESPACE::JoinParam4APIUser& apiParam = joinParam.param.apiuserJoin;
		apiParam.meetingNumber = _wcstoui64(meetingnumber, NULL, 10);
		apiParam.userName = username;
		apiParam.psw = usertoken;

		int ret = m_pMeetingServiceMgr->Join(joinParam);
		m_pSink->ShowStatus(ret, L"clsZoomMgr::ApiUserJoin ret");
		return ret;

	}
	bool Leave() 
	{
		if (m_pMeetingServiceMgr == NULL)
			return false;

		return m_pMeetingServiceMgr->Leave();
	}

	bool End()
	{
		if (m_pMeetingServiceMgr == NULL)
			return false;
		return m_pMeetingServiceMgr->End();
	}
};

